package il.ac.braude.sona.table;

import il.ac.braude.sona.database.ChangeRequest;
import il.ac.braude.sona.ocsf.server.DatabaseController;

import java.util.ArrayList;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

public class ChangeRequestTableModel implements TableModel{
	private ArrayList<TableModelListener> listeners = new ArrayList<TableModelListener>();
	private ArrayList<ChangeRequest> mRequests;

	public ChangeRequestTableModel(ArrayList<ChangeRequest> req) {
		mRequests=req;
	}
	public ChangeRequest getChangeRequest(int i) {
		return mRequests.get(i);
	}
	public void addTableModelListener(TableModelListener l) {
		if (!listeners.contains(l))
			listeners.add(l);
	}

	@Override
	public Class<?> getColumnClass(int arg0) {
		return String.class;
	}

	@Override
	public int getColumnCount() {
		return ChangeRequest.fields.length;
	}

	@Override
	public String getColumnName(int i) {
		return ChangeRequest.fields[i];
	}

	@Override
	public int getRowCount() {
		return mRequests.size();
	}

	@Override
	public Object getValueAt(int i, int j) {
		return mRequests.get(i).getValue(getColumnName(j));
	}

	@Override
	public boolean isCellEditable(int arg0, int arg1) {
		return false;
	}

	@Override
	public void removeTableModelListener(TableModelListener l) {
		listeners.remove(l);
	}

	@Override
	public void setValueAt(Object arg0, int arg1, int arg2) {
	}
}
